home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / DEMOS / DEMO4.ARC / !Demo4 / c / simu < prev    next >
Text File  |  1992-04-05  |  5KB  |  210 lines

  1. /******************************************************************************
  2. *                                                                             *
  3. *    grp.c                                                                    *
  4. *                                                                             *
  5. ******************************************************************************/
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <math.h>
  10. #include <swis.h>
  11. #include <os.h>
  12. #include <bbc.h>
  13. #include "GrpLib.h"
  14. #include "extern.h"
  15.  
  16. #define  tmax 950
  17.  
  18. int xorg = 160,yorg = 128,dist = 640;
  19.  
  20. int ra,rs,rt,x,y,z,v;
  21.  
  22. /*****************************************************************************/
  23.  
  24. void reset(void)
  25. {
  26.   ra = 0; rs = 0; rt = 0;
  27.   x = 0; y = 0; z = 0; v = 0;
  28. }
  29.  
  30. /*****************************************************************************/
  31.  
  32. int main()
  33. {
  34.   int  time=0;
  35.   int  msx,msy,msbut,msorgx,msorgy;
  36.   int  kbbut;
  37.   int  stp=2;
  38.   int  collision;
  39.  
  40.   ObjTab  **table;
  41.  
  42.   Object  *obs,*hor,*obj,*plane0;
  43.   Envi    *envi;
  44.  
  45.   Object  *sol1,*sol2,*sol3,*sol4;
  46.   Sol     sold1,sold2,sold3,sold4;
  47.   char    *spr;
  48.   int     *alt;
  49.  
  50.   Object  *tower,*ldzn,*hang1,*hang2,*esiee;
  51.  
  52.   int     t;
  53.   signed char dra,drs,drt,dv;
  54.   signed char traject[tmax][4];
  55.   int     pra,prs,prt,px,py,pz,pv;
  56.  
  57. /***** init grp tools *****/
  58.  
  59.   InitGrp();
  60.   Change2DParm(0,0,319,255);
  61.   Change3DParm(xorg,yorg,dist); 
  62.  
  63. /***** init object table *****/
  64.  
  65.   table = InitPlot(10);
  66.  
  67. /***** set observer and envirronement *****/
  68.  
  69.   obs  = MakeObj("",                    NULL,0);
  70.   PlaceObj(obs,0,0,0,-400,500,-3000);
  71.  
  72.   envi = MakeEnvi(1, 1, 0x30);
  73.   MkVec4(envi->DirecSrc[0],   255,   128,   200,      0);
  74.   MkVec4(envi->PonctSrc[0],     0,  2000,     0, 100000);
  75.  
  76. /***** set horizon *****/
  77.  
  78.   hor  = MakeObj("",                    NULL,0);
  79.   PlaceObj(hor,0,0,0,0,0,0);
  80.  
  81. /***** load fractal mountains *****/
  82.  
  83.   sol1 = MakeObj("",                    NULL,0);
  84.   sol2 = MakeObj("",                    NULL,0);
  85.   sol3 = MakeObj("",                    NULL,0);
  86.   sol4 = MakeObj("",                    NULL,0);
  87.   AddObject(table,sol1,PlotSol,CollisionSol,1,&sold1);  
  88.   AddObject(table,sol2,PlotSol,CollisionSol,1,&sold2);  
  89.   AddObject(table,sol3,PlotSol,CollisionSol,1,&sold3);  
  90.   AddObject(table,sol4,PlotSol,CollisionSol,1,&sold4);  
  91.   PlaceObj(sol1,   0,0,0,     0,   0,     0);
  92.   PlaceObj(sol2,   0,0,0, 30000,   0, 40000);
  93.   PlaceObj(sol3,   0,0,0,-25000,   0, 10000);
  94.   PlaceObj(sol4,   0,0,0,  5000,   0,-30000);
  95.  
  96.   spr = (char *)load("<GrpObj$Dir>.GrndSpr");
  97.   alt = (int  *)load("<GrpObj$Dir>.GrndAlt8");
  98.   InitSol(&sold1,spr,alt,40,40);
  99.   InitSol(&sold2,spr,alt,20,20);
  100.   InitSol(&sold3,spr,alt,30,30);
  101.   InitSol(&sold4,spr,alt,20,20);
  102.  
  103. /***** load airport object *****/
  104.  
  105.   tower  = MakeObj("<GrpObj$Dir>.Tower",  SCH,0);
  106.   AddObject(table,tower ,PlotObj,        NULL,0,NULL);  
  107.   PlaceObj(tower,0,0,0,-1500,0, -2000);
  108.  
  109.   ldzn   = MakeObj("<GrpObj$Dir>.Ldzn",   CVX,0);
  110. /*  AddObject(table,ldzn  ,PlotObj,        NULL,0,NULL); */ 
  111.   PlaceObj(ldzn ,0,0,0,-2500,0,-10000);
  112.  
  113.   hang1  = MakeObj("<GrpObj$Dir>.Hangare",CVX,1);
  114.   AddObject(table,hang1 ,PlotObj,        NULL,0,NULL);  
  115.   PlaceObj(hang1,0,0,0,-1000,0, 35000);
  116.  
  117.   hang2  = MakeObj("<GrpObj$Dir>.Hangare",CVX,2);
  118.   AddObject(table,hang2 ,PlotObj,        NULL,0,NULL);  
  119.   PlaceObj(hang2,0,0,0,-1000,0, 38000);
  120.  
  121.  
  122. /***** load esiee object *****/
  123.  
  124.   esiee  = MakeObj("<GrpObj$Dir>.Esiee",  SCH,3);
  125.   AddObject(table,esiee ,PlotObj,        NULL,0,NULL);  
  126.   PlaceObj(esiee,0,0,0,-10500,0, -000);
  127.  
  128.  
  129. /***** load plane0 and traject *****/
  130.  
  131.   plane0  = MakeObj("<GrpObj$Dir>.plane2", SCH,1);
  132.   AddObject(table,plane0 ,PlotObj,        NULL,0,NULL);  
  133.   PlaceObj(plane0,0,0,0,-2500,200,-2500);
  134.  
  135.   LoadTraject("<Demo4$Dir>.traject",traject,tmax);
  136.  
  137. /***** main loop  of simu *****/
  138.  
  139.   ReadMouse(&msorgx,&msorgy,&msbut);
  140.   v=0;
  141.   obj=obs;
  142.  
  143.   SetMousePos(640,512);
  144.  
  145.   while (1) {
  146.   
  147.   PlaceObj(plane0,0,0,0,-2500,200,-2500);
  148.   pra = 0; prs = 0; prt = 0; pv = 0;
  149.  
  150.   for (t=0 ; t<tmax ; t++) {
  151.  
  152.     SetTxtCurPos(0,0); printf("%d",GetClock()-time);
  153.  /*   SetTxtCurPos(0,0); printf("%d %d %d %d",pra,prs,prt,pv);
  154.    */ time = GetClock();
  155.  
  156.     PlotHorizon(envi,obj,hor);
  157.     PlotObj(envi,obj,ldzn);
  158.     Plot(table,envi,obj);
  159.  
  160.     SwapView(0x00FF);
  161.  
  162.     ReadMouse(&msx,&msy,&msbut);
  163.     msx-=msorgx;
  164.     msy-=msorgy;
  165.  
  166.     kbbut = Inkey();
  167.  
  168.  
  169.     rt = (drt = msx*stp>>6);
  170.     rs = (drs = msy*stp>>7); 
  171.     if (msbut==0x01<<2) ra= (dra =  stp*3);
  172.     if (msbut==0x01<<0) ra= (dra = -stp*3);
  173.     if (msbut==0x01<<1) {
  174.       reset();
  175.     }
  176.     switch (kbbut) {
  177.      case '+' : v+=5; dv =  5; break;
  178.      case '-' : v-=5; dv = -5; break;
  179.      case '6' : x+=50; break;
  180.      case '4' : x-=50; break;
  181.      case '8' : z+=50; break;
  182.      case '2' : z-=50; break;
  183.      case 'o' : obj = obs; break;
  184.      case 's' : obj = plane0; v=0; break;
  185.      case ' ' : return(0);
  186.     }
  187.  
  188.     pra = traject[t][0];
  189.     prs = traject[t][1];
  190.     prt = traject[t][2];
  191.     pv  += traject[t][3]; 
  192.     MoveObj(plane0, pra, prs, prt, pv);
  193.  
  194.     MoveObj(obs, ra, rs, rt, v);ra=0;
  195.  
  196.     collision = CollisionHorizon(obs,hor);
  197.     if (!collision) collision = Collision(table,obs);
  198.     if ( collision) {
  199.       obs->Org[1] = collision + 200;
  200.       reset();
  201.       SetTxtCurPos(5,0);
  202.       printf("collision%c",0x07);
  203.     }
  204.  
  205.   }
  206.  
  207.   }
  208.  
  209. }
  210.